Bitwise operators combine bits within one or two int or long values.
If an operand is shorter than an int, it is promoted to int before doing the operations.
Right shift >> n is Arithmetic Shift equivalent of dividing left operand by 2
n
which preserves operand sign.
AND, OR, XOR and NOT do not change the value of operands.
Bitwise
//TEST VARIABLES.
int left = Integer.parseInt ("11011", 2);
int right = Integer.parseInt ("10010", 2);
//BITWISE OPERATORS.
int and = left & right; //10010. 1 if both bits are 1.
int or = left | right; //11011. 1 if either bit is 1.
int xor = left ^ right; //01001. 1 if bits are different.
int invert = ~left; //00100. Invert bits.
int shiftLeft = left << 3; //11011000. Shift bits to the left by 3. Fill with 0.
int shiftRight = left >> 2; //110. Shift bits to the right by 2. Fill with 0.
int shiftRight2 = left >>> 2; //????
//DISPLAY RESULTS.
System.out.println (Integer.toBinaryString(and)); //Display in Binary Format